import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)



const routes = [
  {
    path: '/',
    name: 'Main',
    component: () => import('../views/Main.vue'),
    children: [{
        path: '/home',
        // 别名
        alias: '',
        name: 'Home',
        component: () => import('../views/Home.vue')
      },
      {
        path: '/menu',
        name: 'Menu',
        component: () => import('../views/Menu.vue')
      },
      {
        path: '/shopbag',
        name: 'Shopbag',
        component: () => import('../views/Shopbag.vue')
      },
      {
        path: '/my',
        name: 'My',
        component: () => import('../views/My.vue')
      }
    ]
  },
  {
    path:'/detail/:pID',
    name:'Detail',
    component:() => import('../views/Detail')
  },
  {
    path:'/login',
    name:'Login',
    component:() => import('../views/Login')
  },
  {
    path:'/register',
    name:'Register',
    component:() => import('../views/Register')
  },
  {
    path:'/userdata',
    name:'Userdata',
    component:() => import('../views/Userdata')
  },
  {
    path:'/addressmanage',
    name:'Addressmanage',
    component:() => import('../views/Addressmanage')
  },
  {
    path:'/newaddress',
    name:'Newaddress',
    component:() => import('../views/Newaddress')
  },
  {
    path:'/editaddress',
    name:'Editaddress',
    component:() => import('../views/Editaddress')
  },
  {
    path:'/orderaccount',
    name:'Orderaccount',
    component:() => import('../views/Orderaccount')
  },
  {
    path:'/forgetpassword',
    name:'Forgetpassword',
    component:() => import('../views/Forgetpassword')
  },
  {
    path:'/search',
    name:'Search',
    component:() => import('../views/Search')
  },
  {
    path:'/userlike',
    name:'Userlike',
    component:() => import('../views/Userlike')
  },
  {
    path:'/myorder',
    name:'Myorder',
    component:() => import('../views/Myorder'),
    children:[
      {
        path:'/navall',
         // 别名
         alias: '',
        name:'Navall',
        component:() => import('../views/Navall')
      },
      {
        path:'/naving',
        name:'Naving',
        component:() => import('../views/Naving')
      },
      {
        path:'/naved',
        name:'Naved',
        component:() => import('../views/Naved')
      },
    ]
  },
  {
    path:'/tosafe',
    name:'Tosafe',
    component:() => import('../views/Tosafe')
  }
]

const router = new VueRouter({
  routes
})

// 项目中报错Error: Avoided redundant navigation to current location: “/xxx“.的解决方案
// 重复点击‘我的订单’页面的子路由时，会报错，虽然不影响使用。加了这段代码解决问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router